home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
038a
/
bas_int1.zip
/
@ISFILE.BAS
< prev
next >
Wrap
BASIC Source File
|
1991-07-03
|
2KB
|
67 lines
'================================================================
'Two (2) routines are shown here to test for the existence
'of a file. One uses CALL INTERRUPT.
'=================================================================
'Quick Basic Forum
' Date : 28-Jun-91
' From : Dick Dennison
'Subject : Re: If Exist (file$) then
'------------------------------------------------------------------
DECLARE FUNCTION Exist! (FileSpec$)
'$INCLUDE: 'qb.bi' 'Supply correct path and start QB /L QB
a% = Exist("filename.ext")
IF a% = -1 THEN PRINT "Exists" ELSE PRINT "Not found"
FUNCTION Exist (FileSpec$)
DIM regs AS RegTypeX
DIM DTA AS STRING * 44
Temp$ = FileSpec$ + CHR$(0)
regs.ax = &H1A00 'DOS service to set DTA
regs.ds = VARSEG(DTA)
regs.dx = VARPTR(DTA)
CALL INTERRUPTX(&H21, regs, regs)
regs.ax = &H4E00 'Find first matching file
regs.cx = 0
regs.ds = VARSEG(Temp$)
regs.dx = SADD(Temp$)
CALL INTERRUPTX(&H21, regs, regs)
IF regs.ax AND 255 THEN
Exist = 0
ELSE
Exist = -1
END IF
END FUNCTION
'-------------------------------------------------------------------
' Quick Basic Forum
' Date : 30-Jun-91
' From : Steve Halko
'Subject : Re: If Exist (file$) then
'Another method avoiding use of ON ERROR:
'--------------------------------------------------------------------
FUNCTION Exist(FileName$) AS INTEGER
FileNr = FREEFILE
OPEN FileName$ FOR BINARY AS FileNr
IF LOF(FileNr) THEN
Exist = -1
CLOSE FileNr
ELSE
Exist = 0
CLOSE FileNr
KILL FileName$
ENDIF
END FUNCTION
'This uses the fact that if you open a file for BINARY and the file
'didn't exist, then QB will create a file of length 0. Of course, this
'won't work if you're trying to test for file of length 0 which already
'exists.